import React from "react";
import ReactDOM from "react-dom";

import URL from '../http/URL';
// import {post,get} from '../http/Fetch';
import { ToastShow } from "../utils/CommonUtil";
import { post1, get1 } from "../http/Fetch";

class Index1 extends React.Component {

    constructor(props){
        super(props);
        // 创建 ref 存储 textInput DOM 元素
        this.textInput = React.createRef();
        this.focusTextInput = this.focusTextInput.bind(this);
    }

    focusTextInput() {
        // 直接使用原生 API 使 text 输入框获得焦点
        // 注意：通过 "current" 取得 DOM 节点
        this.textInput.current.focus();
    }



    // state={
    //     loginName: "",
    //     password: "",
    // }

    componentDidMount(){
        // get1(URL.getData,{id:0},this,function(i){
        //     console.log(i);
        //     // console.log(code);
        // });
    }
    
    toLogin(){
        // console.log(this);
        let params={
            loginName: this.state.loginName,
            password: this.state.password,
            sim: "123"
        };
        console.log(params);
        // console.log(URL.getLoginInfo);
        

        let that = this;
            // post1(URL.getLoginInfo,params,this,function(data){
            //     // console.log(that);
            //     // console.log(data);
            //     if (data.stat==="1") {
            //         that.props.history.push("/hello");
            //     } else {
            //         ToastShow('用户名或密码输入错误');
            //     }
            // });

    }
    
 
    render() {
        
        return (
            <div className="index-contain">
                用户名<input onChange={e => this.setState({ loginName: e.target.value })} ref={this.textInput}/><br/>
                密码<input onChange={e => this.setState({ password: e.target.value })} onClick={this.focusTextInput} /><br />
                <button onClick={this.toLogin.bind(this)}>登录</button>
            </div>)
     }
}
export default Index1;
